﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Sale_Common;
using Sale_Model;
using Sale_Operation;
using ExtAspNet;

namespace SaleSystem.Other
{
    public partial class frm_SysConfig : PageBase
    {

        #region Page Event
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
                GetAndBind();
        }

        protected void bnSave_Click(object sender, EventArgs e)
        {
            //保存
            bool blRes = false;
            SysConfig SM = new SysConfig();
            SM.SConf_Id = 4;
            SM.SConf_Value = this.ddl4.SelectedValue;
            blRes = Manager.Save(SM);
            if (blRes)
            {
                SM.SConf_Id = 5;
                SM.SConf_Value = this.ddl5.SelectedValue;
                blRes = Manager.Save(SM);
            }
            else
            {
                ExtAspNet.Alert.ShowInParent("配置结算方式与帐户绑定关系出错！");
                return;
            }
            if (blRes)
            {
                SM.SConf_Id = 1;
                SM.SConf_Value = this.tb_SystemName.Text;
                blRes = Manager.Save(SM);
            }
            else
            {
                ExtAspNet.Alert.ShowInParent("系统名称保存出错！");
                return;
            }
            if (blRes)
            {
                SM.SConf_Id = 2;
                SM.SConf_Value = this.tb_Version.Text;
                blRes=Manager.Save(SM);
            }
            else
            {
                ExtAspNet.Alert.ShowInParent("系统名称保存出错！");
                return; 
            }
            if (blRes)
            {
                SM.SConf_Id = 3;
                SM.SConf_Value = this.tb_PageSize.Text;
                blRes=Manager.Save(SM);
                LinkService.PageSize = ValueHandler.GetIntNumberValue( SM.SConf_Value);
            }
            else
            {
                ExtAspNet.Alert.ShowInParent("系统名称保存出错！");
                return;
            }
            if (blRes)
            {
                SM.SConf_Id = 6;
                SM.SConf_Value = this.tb_url.Text;
                blRes = Manager.Save(SM);
               
            }
            else
            {
                ExtAspNet.Alert.ShowInParent("首页地址保存出错！");
                return;
            }
            if (blRes)
            {
                ExtAspNet.Alert.ShowInParent("配置信息保存完成！", "操作提示！", MessageBoxIcon.Information);
            }
        }
        protected void bnReload_Click(object sender, EventArgs e)
        {
            GetAndBind();
        }
        protected void GetAndBind()
        {
            //加载帐户
            AccountListOp AccountManager = new AccountListOp();
            DataTable dt1= AccountManager.GetList("");
            this.ddl4.DataSource = dt1;
            this.ddl4.DataBind();
            this.ddl4.Items.Insert(0, new ExtAspNet.ListItem("-未选择-", "-1"));
            this.ddl5.DataSource = dt1;
            this.ddl5.DataBind();
            this.ddl5.Items.Insert(0, new ExtAspNet.ListItem("-未选择-", "-1"));

            SysConfig SM = new SysConfig();
            SM.SConf_Id = 4;//现金结算
            Manager.GetConfig(SM);
            this.ddl4.SelectedValue = SM.SConf_Value.ToString();
            
            SM.SConf_Id = 5;//刷卡结算
            Manager.GetConfig(SM);

            this.ddl5.SelectedValue = SM.SConf_Value.ToString();

            //系统名称
            SM.SConf_Id = 1;
            Manager.GetConfig(SM);
            this.tb_SystemName.Text = SM.SConf_Value;

            //版本号
            SM.SConf_Id = 2;
            Manager.GetConfig(SM);
            this.tb_Version.Text = SM.SConf_Value;
            //页面大小
            SM.SConf_Id = 3;
            Manager.GetConfig(SM);
            this.tb_PageSize.Text = SM.SConf_Value;
            SM.SConf_Id = 6;
            Manager.GetConfig(SM);
            this.tb_url.Text = SM.SConf_Value;
        }

        #endregion
        #region Property
        SysConfigOp Manager = new SysConfigOp();
        #endregion
    }
}
